定制Android ListView 快速滚动的滚动条-fast scroll bar thumb

1.方法一

View Code
    private void initScrollBar() {
        try {
            Field f = AbsListView.class.getDeclaredField("mFastScroller");
            f.setAccessible(true);
            Object o = f.get(mListView);
            f = f.getType().getDeclaredField("mThumbDrawable");
            f.setAccessible(true);
            Drawable drawable = (Drawable) f.get(o);
            drawable = getResources().getDrawable(R.drawable.music_slider);
            f.set(o, drawable);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

2.方法二

在style.xml中定义主题

View Code
    <style name="audiotheme" parent="android:Theme">
        <item name="android:fastScrollTrackDrawable">@drawable/music_scroll_slider_background</item>
        <item name="android:fastScrollThumbDrawable">@drawable/music_slider</item>
    </style>

在AndroidManifest.xml中应用

    <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/audiotheme" >

 

posted @ 2013-01-22 14:24  qiangzhu  阅读(3562)  评论(0编辑  收藏  举报